﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Asteroids
{
    public class Camera
    {
        Viewport m_viewport;
        public Vector2 position, origin;
        public int X, Y, oX, oY;

        public Rectangle screenBounds
        {
            get { return new Rectangle(X, Y, m_viewport.Width, m_viewport.Height); }
        }

        public Camera(Viewport viewport)
        {
            oX = viewport.Width / 2;
            oY = viewport.Height / 2;
            m_viewport = viewport;
        }

        public void Move(Vector2 amount)
        {
            oX += (int)amount.X;
            oY += (int)amount.Y;
        }

        public void LookAt(SpaceItem target)
        {
            LookAt(target.centerPosition);       
        }

        public void LookAt(Vector2 coords)
        {
            Vector2 newPos = coords - new Vector2(m_viewport.Width / 2, m_viewport.Height / 2);
            X = (int)newPos.X;
            Y = (int)newPos.Y;
        }

        public Matrix GetViewMatrix(Vector2 parallax)
        {
            position = new Vector2(X, Y);
            // To add parallax, simply multiply it by the position
            return Matrix.CreateTranslation(new Vector3(-position * parallax, 0.0f));
        }
    }
}
